/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inteligenciaartificial;

import java.awt.Cursor;
import java.util.ArrayList;
import org.jdesktop.beansbinding.Binding;

/**
 *
 * @author Leo
 */
public class VisorPoblacion extends javax.swing.JDialog {

    Generacion generacion;
    int indiceUltimaGeneracion;
    int[] seleccionados;
    
    public VisorPoblacion(int indiceGeneracion, int totalGeneraciones) {
        initComponents();
        tablaGeneracion.setCellSelectionEnabled(true);
        tablaGeneracion.setRowSelectionAllowed(true);
        tablaGeneracion.setColumnSelectionAllowed(false);
        
        indiceUltimaGeneracion= totalGeneraciones;
        
        seleccionados= new int[totalGeneraciones+1];
        for(int i=0;i<seleccionados.length;i++){
            seleccionados[i]=-1;
        }
        
        mostrarGeneracion(indiceGeneracion);
    }
    
     public VisorPoblacion(int indiceGeneracion,int totalGeneraciones, int nroIndividuoSeleccionado) {      
         this(indiceGeneracion, totalGeneraciones);
         tablaGeneracion.changeSelection(nroIndividuoSeleccionado, 0, false, false);
         seleccionados[indiceGeneracion]= nroIndividuoSeleccionado;
         actualizarInfoIndividuo(tablaGeneracion.getSelectedRow());
    }

    private VisorPoblacion() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void mostrarGeneracion(int indiceGeneracion) {
        this.lblNroGeneracion.setText(new Integer(indiceGeneracion).toString());
        generacion = GeneracionManager.getGeneracionNumero(indiceGeneracion);
        
        Binding b = bindingGroup.getBinding("bindingTablaIndividuos");
        b.unbind();
        
        arrayIndividuos.clear();
        
        for(int i=0;i<Settings.totalPoblacion;i++){
            arrayIndividuos.add(new IndividuoData(generacion.getIndividuoNumero(i)));
        }
        b.bind();
        tablaGeneracion.repaint();
        
        if(seleccionados[indiceGeneracion]!=-1){
            tablaGeneracion.changeSelection(seleccionados[indiceGeneracion], 0, false, false);
            actualizarInfoIndividuo(tablaGeneracion.getSelectedRow());
        }else{
            limpiarInfoIndividuo();
        }
        
        actualizarBotones();
    }
    
    private void mostrarGeneracion(int indiceGeneracion, int individuoSeleccionado) {
        this.lblNroGeneracion.setText(new Integer(indiceGeneracion).toString());
        generacion = GeneracionManager.getGeneracionNumero(indiceGeneracion);
        
        Binding b = bindingGroup.getBinding("bindingTablaIndividuos");
        b.unbind();
        
        arrayIndividuos.clear();
        
        for(int i=0;i<Settings.totalPoblacion;i++){
            arrayIndividuos.add(new IndividuoData(generacion.getIndividuoNumero(i)));
        }
        b.bind();
        tablaGeneracion.repaint();
        
        
       tablaGeneracion.changeSelection(individuoSeleccionado, 0, false, false);
       actualizarInfoIndividuo(tablaGeneracion.getSelectedRow());
       seleccionados[indiceGeneracion]= individuoSeleccionado;
        
        actualizarBotones();
    }
    
    private void actualizarBotones() {
        if(generacion.getNroDeGeneracion()==0){
            btnPrimerGeneracion.setEnabled(false);
            btnAnteriorGeneracion.setEnabled(false);
            btnSiguienteGeneracion.setEnabled(true);
            btnUltimaGeneracion.setEnabled(true);
            return;
        }
        if(generacion.getNroDeGeneracion()>0 && generacion.getNroDeGeneracion()<indiceUltimaGeneracion){
            btnPrimerGeneracion.setEnabled(true);
            btnAnteriorGeneracion.setEnabled(true);
            btnSiguienteGeneracion.setEnabled(true);
            btnUltimaGeneracion.setEnabled(true);
            return;
        }
        if(generacion.getNroDeGeneracion()==indiceUltimaGeneracion){
            btnPrimerGeneracion.setEnabled(true);
            btnAnteriorGeneracion.setEnabled(true);
            btnSiguienteGeneracion.setEnabled(false);
            btnUltimaGeneracion.setEnabled(false); 
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        arrayIndividuos = new java.util.ArrayList<IndividuoData>();
        panelScroll = new javax.swing.JScrollPane();
        tablaGeneracion = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblP2M7 = new javax.swing.JLabel();
        lblP2 = new javax.swing.JLabel();
        lblP3 = new javax.swing.JLabel();
        lblP4 = new javax.swing.JLabel();
        lblP1 = new javax.swing.JLabel();
        lblP1M1 = new javax.swing.JLabel();
        lblP2M1 = new javax.swing.JLabel();
        lblP3M1 = new javax.swing.JLabel();
        lblP4M1 = new javax.swing.JLabel();
        lblP3M2 = new javax.swing.JLabel();
        lblP4M2 = new javax.swing.JLabel();
        lblP1M2 = new javax.swing.JLabel();
        lblP2M2 = new javax.swing.JLabel();
        lblP3M3 = new javax.swing.JLabel();
        lblP4M3 = new javax.swing.JLabel();
        lblP1M3 = new javax.swing.JLabel();
        lblP2M3 = new javax.swing.JLabel();
        lblP1M4 = new javax.swing.JLabel();
        lblP2M4 = new javax.swing.JLabel();
        lblP3M4 = new javax.swing.JLabel();
        lblP4M4 = new javax.swing.JLabel();
        lblP3M5 = new javax.swing.JLabel();
        lblP4M5 = new javax.swing.JLabel();
        lblP1M5 = new javax.swing.JLabel();
        lblP2M5 = new javax.swing.JLabel();
        lblP3M6 = new javax.swing.JLabel();
        lblP4M6 = new javax.swing.JLabel();
        lblP1M6 = new javax.swing.JLabel();
        lblP2M6 = new javax.swing.JLabel();
        lblP3M7 = new javax.swing.JLabel();
        lblP4M7 = new javax.swing.JLabel();
        lblP1M8 = new javax.swing.JLabel();
        lblP2M8 = new javax.swing.JLabel();
        lblP3M8 = new javax.swing.JLabel();
        lblP4M8 = new javax.swing.JLabel();
        lblP1M7 = new javax.swing.JLabel();
        panelControlGeneraciones = new javax.swing.JPanel();
        lblNroGeneracion = new javax.swing.JLabel();
        btnPrimerGeneracion = new javax.swing.JButton();
        btnAnteriorGeneracion = new javax.swing.JButton();
        btnSiguienteGeneracion = new javax.swing.JButton();
        btnUltimaGeneracion = new javax.swing.JButton();
        jLabel99 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(800, 600));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        panelScroll.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        panelScroll.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                panelScrollMouseClicked(evt);
            }
        });

        tablaGeneracion.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, arrayIndividuos, tablaGeneracion, "bindingTablaIndividuos");
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nroIndividuo}"));
        columnBinding.setColumnName("Individuo");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cantidadProducto1}"));
        columnBinding.setColumnName("Producto 1");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cantidadProducto2}"));
        columnBinding.setColumnName("Producto 2");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cantidadProducto3}"));
        columnBinding.setColumnName("Producto 3");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cantidadProducto4}"));
        columnBinding.setColumnName("Producto 4");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${utilidad}"));
        columnBinding.setColumnName("Utilidad");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${padre}"));
        columnBinding.setColumnName("Padre");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${madre}"));
        columnBinding.setColumnName("Madre");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${operador}"));
        columnBinding.setColumnName("Operador");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        tablaGeneracion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaGeneracionMouseClicked(evt);
            }
        });
        tablaGeneracion.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                tablaGeneracionMouseMoved(evt);
            }
        });
        tablaGeneracion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tablaGeneracionKeyPressed(evt);
            }
        });
        panelScroll.setViewportView(tablaGeneracion);
        tablaGeneracion.getColumnModel().getColumn(0).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(1).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(2).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(3).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(4).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(5).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(6).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(7).setResizable(false);
        tablaGeneracion.getColumnModel().getColumn(8).setResizable(false);

        getContentPane().add(panelScroll, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 770, 390));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Cantidades");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Producto");
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, -1, -1));

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setText("Material 1");
        jPanel1.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 10, -1, -1));

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel15.setText("Material 2");
        jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 10, -1, -1));

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel16.setText("Material 3");
        jPanel1.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 10, -1, -1));

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel17.setText("Material 4");
        jPanel1.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 10, -1, -1));

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel18.setText("Material 5");
        jPanel1.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 10, -1, -1));

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel19.setText("Material 6");
        jPanel1.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 10, -1, -1));

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel20.setText("Material 7");
        jPanel1.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 10, -1, -1));

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel21.setText("Material 8");
        jPanel1.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 10, -1, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Producto 4");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 100, -1, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Producto 1");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, -1, -1));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Producto 2");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, -1, -1));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Producto 3");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, -1, -1));
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, 730, 10));

        lblP2M7.setText("0");
        jPanel1.add(lblP2M7, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 60, -1, -1));

        lblP2.setText("0");
        jPanel1.add(lblP2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 60, -1, -1));

        lblP3.setText("0");
        jPanel1.add(lblP3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 80, -1, -1));

        lblP4.setText("0");
        jPanel1.add(lblP4, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 100, -1, -1));

        lblP1.setText("0");
        jPanel1.add(lblP1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 40, -1, -1));

        lblP1M1.setText("0");
        jPanel1.add(lblP1M1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 40, -1, -1));

        lblP2M1.setText("0");
        jPanel1.add(lblP2M1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 60, -1, -1));

        lblP3M1.setText("0");
        jPanel1.add(lblP3M1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 80, -1, -1));

        lblP4M1.setText("0");
        jPanel1.add(lblP4M1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 100, -1, -1));

        lblP3M2.setText("0");
        jPanel1.add(lblP3M2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 80, -1, -1));

        lblP4M2.setText("0");
        jPanel1.add(lblP4M2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 100, -1, -1));

        lblP1M2.setText("0");
        jPanel1.add(lblP1M2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 40, -1, -1));

        lblP2M2.setText("0");
        jPanel1.add(lblP2M2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 60, -1, -1));

        lblP3M3.setText("0");
        jPanel1.add(lblP3M3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 80, -1, -1));

        lblP4M3.setText("0");
        jPanel1.add(lblP4M3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 100, -1, -1));

        lblP1M3.setText("0");
        jPanel1.add(lblP1M3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 40, -1, -1));

        lblP2M3.setText("0");
        jPanel1.add(lblP2M3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 60, -1, -1));

        lblP1M4.setText("0");
        jPanel1.add(lblP1M4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 40, -1, -1));

        lblP2M4.setText("0");
        jPanel1.add(lblP2M4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 60, -1, -1));

        lblP3M4.setText("0");
        jPanel1.add(lblP3M4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 80, -1, -1));

        lblP4M4.setText("0");
        jPanel1.add(lblP4M4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 100, -1, -1));

        lblP3M5.setText("0");
        jPanel1.add(lblP3M5, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 80, -1, -1));

        lblP4M5.setText("0");
        jPanel1.add(lblP4M5, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 100, -1, -1));

        lblP1M5.setText("0");
        jPanel1.add(lblP1M5, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 40, -1, -1));

        lblP2M5.setText("0");
        jPanel1.add(lblP2M5, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 60, -1, -1));

        lblP3M6.setText("0");
        jPanel1.add(lblP3M6, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 80, -1, -1));

        lblP4M6.setText("0");
        jPanel1.add(lblP4M6, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 100, -1, -1));

        lblP1M6.setText("0");
        jPanel1.add(lblP1M6, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 40, -1, -1));

        lblP2M6.setText("0");
        jPanel1.add(lblP2M6, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 60, -1, -1));

        lblP3M7.setText("0");
        jPanel1.add(lblP3M7, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 80, -1, -1));

        lblP4M7.setText("0");
        jPanel1.add(lblP4M7, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 100, -1, -1));

        lblP1M8.setText("0");
        jPanel1.add(lblP1M8, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 40, -1, -1));

        lblP2M8.setText("0");
        jPanel1.add(lblP2M8, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 60, -1, -1));

        lblP3M8.setText("0");
        jPanel1.add(lblP3M8, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 80, -1, -1));

        lblP4M8.setText("0");
        jPanel1.add(lblP4M8, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 100, -1, -1));

        lblP1M7.setText("0");
        jPanel1.add(lblP1M7, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 40, -1, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 450, 770, 120));

        panelControlGeneraciones.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        panelControlGeneraciones.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblNroGeneracion.setFont(lblNroGeneracion.getFont().deriveFont(lblNroGeneracion.getFont().getStyle() | java.awt.Font.BOLD, lblNroGeneracion.getFont().getSize()+1));
        lblNroGeneracion.setText("0");
        panelControlGeneraciones.add(lblNroGeneracion, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 10, -1, 30));

        btnPrimerGeneracion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/Skip-backward24.png"))); // NOI18N
        btnPrimerGeneracion.setToolTipText("Ver 50 generaciones atrás");
        btnPrimerGeneracion.setFocusPainted(false);
        btnPrimerGeneracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrimerGeneracionActionPerformed(evt);
            }
        });
        panelControlGeneraciones.add(btnPrimerGeneracion, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 10, -1, -1));

        btnAnteriorGeneracion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/Fast-backward24.png"))); // NOI18N
        btnAnteriorGeneracion.setToolTipText("Ver la generación anterior");
        btnAnteriorGeneracion.setFocusPainted(false);
        btnAnteriorGeneracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorGeneracionActionPerformed(evt);
            }
        });
        panelControlGeneraciones.add(btnAnteriorGeneracion, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 10, -1, -1));

        btnSiguienteGeneracion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/Fast-forward24.png"))); // NOI18N
        btnSiguienteGeneracion.setToolTipText("Ver la generación siguiente");
        btnSiguienteGeneracion.setFocusPainted(false);
        btnSiguienteGeneracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSiguienteGeneracionActionPerformed(evt);
            }
        });
        panelControlGeneraciones.add(btnSiguienteGeneracion, new org.netbeans.lib.awtextra.AbsoluteConstraints(630, 10, -1, -1));

        btnUltimaGeneracion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/Skip-forward24.png"))); // NOI18N
        btnUltimaGeneracion.setToolTipText("Ver 50 generacones adelante");
        btnUltimaGeneracion.setFocusPainted(false);
        btnUltimaGeneracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUltimaGeneracionActionPerformed(evt);
            }
        });
        panelControlGeneraciones.add(btnUltimaGeneracion, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 10, -1, -1));

        jLabel99.setFont(new java.awt.Font("Lucida Grande", 1, 13)); // NOI18N
        jLabel99.setText("Mostrando generación número:");
        panelControlGeneraciones.add(jLabel99, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 30));

        getContentPane().add(panelControlGeneraciones, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 770, 50));

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void panelScrollMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelScrollMouseClicked
 
    }//GEN-LAST:event_panelScrollMouseClicked

    private void tablaGeneracionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaGeneracionMouseClicked
        Cursor cursorAnterior= tablaGeneracion.getCursor();
        tablaGeneracion.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        
        if(tablaGeneracion.columnAtPoint(evt.getPoint())==6){
            Individuo ind= generacion.getIndividuoNumero(tablaGeneracion.getSelectedRow());
            if(ind.getNroGeneracion()==0){
                tablaGeneracion.setCursor(cursorAnterior);
                return;
            }
            mostrarGeneracion(ind.getNroGeneracionPadre(), ind.getNroIndividuoPadre());  
            tablaGeneracion.setCursor(cursorAnterior);
            return;
        }
        
        if( tablaGeneracion.columnAtPoint(evt.getPoint())==7){
            Individuo ind= generacion.getIndividuoNumero(tablaGeneracion.getSelectedRow());
            if(ind.getNroGeneracion()==0){
                tablaGeneracion.setCursor(cursorAnterior);
                return;
            }
            //verificar que madre sea valido
            if(ind.tieneMadre()){
                mostrarGeneracion(ind.getNroGeneracionMadre(), ind.getNroIndividuoMadre());
                tablaGeneracion.setCursor(cursorAnterior);
                return;
            }
        }
   
        //sacualizo los labels del individuo
        actualizarInfoIndividuo(tablaGeneracion.getSelectedRow());
        seleccionados[generacion.getNroDeGeneracion()]= tablaGeneracion.getSelectedRow();
        
        tablaGeneracion.setCursor(cursorAnterior);
    }//GEN-LAST:event_tablaGeneracionMouseClicked

    private void tablaGeneracionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaGeneracionKeyPressed
        actualizarInfoIndividuo(tablaGeneracion.getSelectedRow());
        seleccionados[generacion.getNroDeGeneracion()]= tablaGeneracion.getSelectedRow();
    }//GEN-LAST:event_tablaGeneracionKeyPressed

    private void tablaGeneracionMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaGeneracionMouseMoved
        if(tablaGeneracion.columnAtPoint(evt.getPoint())==6 && generacion.getNroDeGeneracion()!=0){
            tablaGeneracion.setCursor(new Cursor(Cursor.HAND_CURSOR));
            return;
        }
        if( tablaGeneracion.columnAtPoint(evt.getPoint())==7 && generacion.getNroDeGeneracion()!=0){
            Individuo ind= generacion.getIndividuoNumero(tablaGeneracion.rowAtPoint(evt.getPoint()));
            if(ind.tieneMadre()){
                tablaGeneracion.setCursor(new Cursor(Cursor.HAND_CURSOR));
                 return;
            }
        }

        tablaGeneracion.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_tablaGeneracionMouseMoved

    private void btnPrimerGeneracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrimerGeneracionActionPerformed
       panelControlGeneraciones.setCursor(new Cursor(Cursor.WAIT_CURSOR));
       int i= generacion.getNroDeGeneracion()-50;
       if(i<0) i=0;
       mostrarGeneracion(i);
       panelControlGeneraciones.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_btnPrimerGeneracionActionPerformed

    private void btnAnteriorGeneracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorGeneracionActionPerformed
       panelControlGeneraciones.setCursor(new Cursor(Cursor.WAIT_CURSOR));
       mostrarGeneracion(generacion.getNroDeGeneracion()-1); 
       panelControlGeneraciones.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_btnAnteriorGeneracionActionPerformed

    private void btnSiguienteGeneracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSiguienteGeneracionActionPerformed
       panelControlGeneraciones.setCursor(new Cursor(Cursor.WAIT_CURSOR));
       mostrarGeneracion(generacion.getNroDeGeneracion()+1); 
       panelControlGeneraciones.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_btnSiguienteGeneracionActionPerformed

    private void btnUltimaGeneracionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUltimaGeneracionActionPerformed
       panelControlGeneraciones.setCursor(new Cursor(Cursor.WAIT_CURSOR));
       int i= generacion.getNroDeGeneracion()+50;
       if(i>indiceUltimaGeneracion) i=indiceUltimaGeneracion;
       mostrarGeneracion(i);
       panelControlGeneraciones.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_btnUltimaGeneracionActionPerformed

    private void actualizarInfoIndividuo(int nroIndividuo) {
        
        if(nroIndividuo<0 || nroIndividuo>=Settings.totalPoblacion) return;
        
        Individuo ind= generacion.getIndividuoNumero(nroIndividuo);
        lblP1.setText(new Integer(ind.getCantidadProducto(1)).toString());
        lblP1M1.setText(new Integer(ind.getCantidadMaterial(1, 1)).toString());
        lblP1M2.setText(new Integer(ind.getCantidadMaterial(1, 2)).toString());
        lblP1M3.setText(new Integer(ind.getCantidadMaterial(1, 3)).toString());
        lblP1M4.setText(new Integer(ind.getCantidadMaterial(1, 4)).toString());
        lblP1M5.setText(new Integer(ind.getCantidadMaterial(1, 5)).toString());
        lblP1M6.setText(new Integer(ind.getCantidadMaterial(1, 6)).toString());
        lblP1M7.setText(new Integer(ind.getCantidadMaterial(1, 7)).toString());
        lblP1M8.setText(new Integer(ind.getCantidadMaterial(1, 8)).toString());
        
        lblP2.setText(new Integer(ind.getCantidadProducto(2)).toString());
        lblP2M1.setText(new Integer(ind.getCantidadMaterial(2, 1)).toString());
        lblP2M2.setText(new Integer(ind.getCantidadMaterial(2, 2)).toString());
        lblP2M3.setText(new Integer(ind.getCantidadMaterial(2, 3)).toString());
        lblP2M4.setText(new Integer(ind.getCantidadMaterial(2, 4)).toString());
        lblP2M5.setText(new Integer(ind.getCantidadMaterial(2, 5)).toString());
        lblP2M6.setText(new Integer(ind.getCantidadMaterial(2, 6)).toString());
        lblP2M7.setText(new Integer(ind.getCantidadMaterial(2, 7)).toString());
        lblP2M8.setText(new Integer(ind.getCantidadMaterial(2, 8)).toString());
        
        lblP3.setText(new Integer(ind.getCantidadProducto(3)).toString());
        lblP3M1.setText(new Integer(ind.getCantidadMaterial(3, 1)).toString());
        lblP3M2.setText(new Integer(ind.getCantidadMaterial(3, 2)).toString());
        lblP3M3.setText(new Integer(ind.getCantidadMaterial(3, 3)).toString());
        lblP3M4.setText(new Integer(ind.getCantidadMaterial(3, 4)).toString());
        lblP3M5.setText(new Integer(ind.getCantidadMaterial(3, 5)).toString());
        lblP3M6.setText(new Integer(ind.getCantidadMaterial(3, 6)).toString());
        lblP3M7.setText(new Integer(ind.getCantidadMaterial(3, 7)).toString());
        lblP3M8.setText(new Integer(ind.getCantidadMaterial(3, 8)).toString());
        
        lblP4.setText(new Integer(ind.getCantidadProducto(4)).toString());
        lblP4M1.setText(new Integer(ind.getCantidadMaterial(4, 1)).toString());
        lblP4M2.setText(new Integer(ind.getCantidadMaterial(4, 2)).toString());
        lblP4M3.setText(new Integer(ind.getCantidadMaterial(4, 3)).toString());
        lblP4M4.setText(new Integer(ind.getCantidadMaterial(4, 4)).toString());
        lblP4M5.setText(new Integer(ind.getCantidadMaterial(4, 5)).toString());
        lblP4M6.setText(new Integer(ind.getCantidadMaterial(4, 6)).toString());
        lblP4M7.setText(new Integer(ind.getCantidadMaterial(4, 7)).toString());
        lblP4M8.setText(new Integer(ind.getCantidadMaterial(4, 8)).toString());
    }
    
    private void limpiarInfoIndividuo() {
        lblP1.setText(new Integer(0).toString());
        lblP1M1.setText(new Integer(0).toString());
        lblP1M2.setText(new Integer(0).toString());
        lblP1M3.setText(new Integer(0).toString());
        lblP1M4.setText(new Integer(0).toString());
        lblP1M5.setText(new Integer(0).toString());
        lblP1M6.setText(new Integer(0).toString());
        lblP1M7.setText(new Integer(0).toString());
        lblP1M8.setText(new Integer(0).toString());
        
        lblP2.setText(new Integer(0).toString());
        lblP2M1.setText(new Integer(0).toString());
        lblP2M2.setText(new Integer(0).toString());
        lblP2M3.setText(new Integer(0).toString());
        lblP2M4.setText(new Integer(0).toString());
        lblP2M5.setText(new Integer(0).toString());
        lblP2M6.setText(new Integer(0).toString());
        lblP2M7.setText(new Integer(0).toString());
        lblP2M8.setText(new Integer(0).toString());
        
        lblP3.setText(new Integer(0).toString());
        lblP3M1.setText(new Integer(0).toString());
        lblP3M2.setText(new Integer(0).toString());
        lblP3M3.setText(new Integer(0).toString());
        lblP3M4.setText(new Integer(0).toString());
        lblP3M5.setText(new Integer(0).toString());
        lblP3M6.setText(new Integer(0).toString());
        lblP3M7.setText(new Integer(0).toString());
        lblP3M8.setText(new Integer(0).toString());
        
        lblP4.setText(new Integer(0).toString());
        lblP4M1.setText(new Integer(0).toString());
        lblP4M2.setText(new Integer(0).toString());
        lblP4M3.setText(new Integer(0).toString());
        lblP4M4.setText(new Integer(0).toString());
        lblP4M5.setText(new Integer(0).toString());
        lblP4M6.setText(new Integer(0).toString());
        lblP4M7.setText(new Integer(0).toString());
        lblP4M8.setText(new Integer(0).toString());
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.ArrayList<IndividuoData> arrayIndividuos;
    private javax.swing.JButton btnAnteriorGeneracion;
    private javax.swing.JButton btnPrimerGeneracion;
    private javax.swing.JButton btnSiguienteGeneracion;
    private javax.swing.JButton btnUltimaGeneracion;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabel99;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblNroGeneracion;
    private javax.swing.JLabel lblP1;
    private javax.swing.JLabel lblP1M1;
    private javax.swing.JLabel lblP1M2;
    private javax.swing.JLabel lblP1M3;
    private javax.swing.JLabel lblP1M4;
    private javax.swing.JLabel lblP1M5;
    private javax.swing.JLabel lblP1M6;
    private javax.swing.JLabel lblP1M7;
    private javax.swing.JLabel lblP1M8;
    private javax.swing.JLabel lblP2;
    private javax.swing.JLabel lblP2M1;
    private javax.swing.JLabel lblP2M2;
    private javax.swing.JLabel lblP2M3;
    private javax.swing.JLabel lblP2M4;
    private javax.swing.JLabel lblP2M5;
    private javax.swing.JLabel lblP2M6;
    private javax.swing.JLabel lblP2M7;
    private javax.swing.JLabel lblP2M8;
    private javax.swing.JLabel lblP3;
    private javax.swing.JLabel lblP3M1;
    private javax.swing.JLabel lblP3M2;
    private javax.swing.JLabel lblP3M3;
    private javax.swing.JLabel lblP3M4;
    private javax.swing.JLabel lblP3M5;
    private javax.swing.JLabel lblP3M6;
    private javax.swing.JLabel lblP3M7;
    private javax.swing.JLabel lblP3M8;
    private javax.swing.JLabel lblP4;
    private javax.swing.JLabel lblP4M1;
    private javax.swing.JLabel lblP4M2;
    private javax.swing.JLabel lblP4M3;
    private javax.swing.JLabel lblP4M4;
    private javax.swing.JLabel lblP4M5;
    private javax.swing.JLabel lblP4M6;
    private javax.swing.JLabel lblP4M7;
    private javax.swing.JLabel lblP4M8;
    private javax.swing.JPanel panelControlGeneraciones;
    private javax.swing.JScrollPane panelScroll;
    private javax.swing.JTable tablaGeneracion;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables



}
